package design.action.memento;

import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * @author zxs
 * @since 2020/05/29
 */
public class BoundedQueue<E> extends ConcurrentLinkedDeque<E> {

    private static final long serialVersionUID = -3945953719763255337L;

    private final int size;

    public BoundedQueue(final int size) {
        this.size = size;
    }

    @Override
    public boolean offer(final E object) {
        if (size() == size) {
            this.poll();
        }
        return super.offer(object);
    }
}
